2 Problem: 11088 - End up with More Teams
3 Author: Andrés Mejía-Posada
5 Trying another approach...
6 Works, but slower. Accepted
29 #define D(x) cout << #x " is " << x << endl
30 #define bit(i, n) (n & (1 << i))
32 int memo
[1<<15], x
[15], n
;
35 Returns the maximum amount of teams that can be made using
36 teams set on on bitwise mask avail. At each step, I try to
37 build a new team using all possible valid triplets.
40 int &ans
= memo
[avail
];
43 for (int i
=0; i
<n
; ++i
)
45 for (int j
=i
+1; j
<n
; ++j
)
47 for (int k
=j
+1; k
<n
; ++k
)
49 if(x
[i
] + x
[j
] + x
[k
] >= 20)
50 ans
= max(ans
, 1 + best(avail
& ~(1 << i
) & ~(1 << j
) & ~(1 << k
))); //Make team (i, j, k).
52 //printf("best(%X) = %d\n", avail, ans);
58 while (scanf("%d", &n
) == 1 && n
){
59 for (int i
= 0; i
<n
; ++i
) scanf("%d", &x
[i
]);
61 memset(memo
, -1, sizeof memo
);
62 printf("Case %d: %d\n", pizza
++, best((1 << n
) - 1));